package com.cx.controller;

//import com.cx.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cx.entity.Article;
import com.cx.service.ArticleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;


@Controller
//@RestController
//@RequestMapping("/")
public class UserController {
    @Autowired
    private ArticleService articleService;

    //博客前台用户端首页
    @GetMapping({"/","/page/{pageNo}"})
    public String toUserIndex(Model model, @PathVariable(required = false) Integer pageNo){
        PageHelper.startPage(pageNo==null?1:pageNo,5);
        QueryWrapper<Article> articleQueryWrapper = new QueryWrapper<>();
        articleQueryWrapper.orderByDesc("created");
        PageInfo<Article> pageInfo = new PageInfo<>(articleService.list(articleQueryWrapper));
        model.addAttribute("articles", pageInfo);
        model.addAttribute("articleList", articleService.getHotArticle());
        return "client/index";
    }
//    进入后台管理首页
    @GetMapping("/admin")
    public String toAdminIndex(){
        return "back/index";
    }
//    后台首页欢迎页面的接口
    @GetMapping("/back/page/welcome-1.html")
    public String welcome(){
        return "back/page/welcome-1.html";
    }


//
//    @Autowired
//    private Service userService;

    /**
     * 列表
     */
//    @RequestMapping("/list")
//    //@RequiresPermissions("cx:user:list")
//    public R list(@RequestParam Map<String, Object> params){
//        PageUtils page = userService.queryPage(params);
//
//        return R.ok().put("page", page);
//    }
//
//
//    /**
//     * 信息
//     */
//    @RequestMapping("/info/{id}")
//    //@RequiresPermissions("cx:user:info")
//    public R info(@PathVariable("id") Integer id){
//        UserEntity user = userService.getById(id);
//
//        return R.ok().put("user", user);
//    }
//
//    /**
//     * 保存
//     */
//    @RequestMapping("/save")
//    //@RequiresPermissions("cx:user:save")
//    public R save(@RequestBody UserEntity user){
//        userService.save(user);
//
//        return R.ok();
//    }
//
//    /**
//     * 修改
//     */
//    @RequestMapping("/update")
//    //@RequiresPermissions("cx:user:update")
//    public R update(@RequestBody UserEntity user){
//        userService.updateById(user);
//
//        return R.ok();
//    }
//
//    /**
//     * 删除
//     */
//    @RequestMapping("/delete")
//    //@RequiresPermissions("cx:user:delete")
//    public R delete(@RequestBody Integer[] ids){
//        userService.removeByIds(Arrays.asList(ids));
//
//        return R.ok();
//    }

}
